package com.phx.serialjni;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.Bitmap;
import java.util.HashMap;
import android.graphics.drawable.BitmapDrawable;



public class PageS{
    static int pageno ;
    static int pageback ;
    static Integer[] nodeArray;
    static String[][]  sliderCmd ={
            {"71B00000", "71B10000", "71B20000", "71B30000", "71B40000", "71B50000", "71B60000", "71B70000", "71680000", "71B90000",},
            {"72B00009", "72B10000", "72B20000", "72B30000", "72B40000", "72B50000", "72B60000", "72B70000", "72B80000", "72B90000",},
            {"73B00009", "73B10000", "73B20000", "73B30000", "73B40000", "73B50000", "73B60000", "73B70000", "73B80000", "73B90000",}};
    static String[] allDArray = new String[]{"0071", "0072", "0073", "0074","0075","0076","0081", "0082", "0083", "0084","0085","0086","0087","1010","1011","71b0","72b0","73b0"};
    static String[] voladdress = {"1010","1011"};
    Integer[] seqArray ;
    static Integer[] offArray ;
    static Integer[] onArray ;
    static String[] cmdArray  ;
    static  Integer[] typeArray;
    static String[] feedDArray;
    static int jmpPosition = 0;
    static public  BitmapDrawable[] bmpDraw;
    static public Bitmap  icon;
    static public Bitmap bitmap,bitmapqj,bitmapbj;
    static public Bitmap bitmapp;
    static Rect[]  cmdRect,jumpRect;
    public  static HashMap<String, String> feedMap = new HashMap<String, String>();
    public  static HashMap<String, String> feedType = new HashMap<String, String>();

    static public int height ;
    static public int width ;
    static public int cmdRectNum,jumpRectNum;
    static public Picture[]  page = new Picture[20];

    PageS() {
     for (int ii=0;ii<20;ii++) {
            PageS.page[ii] = new Picture();
            for (int jj=0;jj<20;jj++) {
                page[ii].icon[jj] = new Icon();
            }
        }
    }

    public static void setfeeds() {
        String[] feedDArrayx = new String[]{"d001", "d002", "d003","d004","d005","d006", "0077","0078","0079", "0084","0085","0086","0087","1010","1011","71b0","72b0","73b0"};
        String[] feedDTypex = new String[]{"1", "1", "1", "1","1","1", "1", "1", "1","1","1","1", "1", "2","2","6","6","6"};
        setfeedinit(feedDArrayx,feedDTypex);
    }
    public static void setfeedinit(String[] myDArrayx,String[] myDArray){
        int vv = myDArrayx.length;
        for (int x=0; x<vv; x++) {
            if(!myDArrayx[x].equals("")) {
                feedMap.put(myDArrayx[x],"0000");
               // feedType.put(myDArrayx[x],myDArray[x]);
                //feedType.put(myDArrayx[x],myDArray[x]);
            }
        }
    }
    public void s0() {
        pageno = 0;
        jmpPosition = 0;
        seqArray = new Integer[]{1, 2, 3, 4, 5, 6,7,8,9};
        //typeArray = new Integer[]{20, 20, 20, 19, 19, 19, 19, 19, 19};
        typeArray = new Integer[]{19, 19, 19, 19, 19, 19, 19, 19, 19};
            cmdArray = new String[]{"71100000","72100000",
                    "73100000", "74100000",
                    "75100000",
                    "76100000",
                "77100000",
                "78100000",
                "79100000"};
        nodeArray = new Integer[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
      //  feedDArray = new String[]{"0071", "0072", "0073","0074","0075","0076", "0077","0078","0079"};
        feedDArray = new String[]{"d001", "d002", "d003","d004","d005","d006", "0077","0078","0079"};
        offArray = new Integer[]{R.drawable.b1_off,
                R.drawable.b2_off, R.drawable.b3_off, R.drawable.b1_off,
                R.drawable.b2_off, R.drawable.b3_off, R.drawable.b5_off,R.drawable.b6_off, R.drawable.b7_off};
           onArray = new Integer[]{R.drawable.b1_on,
              R.drawable.b2_on, R.drawable.b3_on,R.drawable.b1_on,
              R.drawable.b2_on, R.drawable.b3_on, R.drawable.b5_on,R.drawable.b6_on, R.drawable.b7_on};
        cmdRect = new Rect[PageS.page[pageno].totalIconNum];
        int rectLeft,rectTop,rectRight,rectBottom,iconNum=0;
        for(int ii=0;ii< PageS.page[pageno].totalIconNum;ii++) {
             cmdRect[ii] =  PageS.page[pageno].icon[ii].iconRect ;
         }
    }
    public void setInit(int currentPage) {
        pageno = currentPage;
        jmpPosition = currentPage;
        seqArray = new Integer[]{1, 2, 3, 4, 5, 6,7,8,9};
        //typeArray = new Integer[]{20, 20, 20, 19, 19, 19, 19, 19, 19};
        typeArray = new Integer[]{19, 19, 19, 19, 19, 19, 19, 19, 19};
        cmdArray = new String[]{"71100000","72100000",
                "73100000", "74100000",
                "75100000",
                "76100000",
                "77100000",
                "78100000",
                "79100000"};
        nodeArray = new Integer[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
        //  feedDArray = new String[]{"0071", "0072", "0073","0074","0075","0076", "0077","0078","0079"};
        feedDArray = new String[]{"d001", "d002", "d003","d004","d005","d006", "0077","0078","0079"};
        offArray = new Integer[]{R.drawable.b1_off,
                R.drawable.b2_off, R.drawable.b3_off, R.drawable.b1_off,
                R.drawable.b2_off, R.drawable.b3_off, R.drawable.b5_off,R.drawable.b6_off, R.drawable.b7_off};
        onArray = new Integer[]{R.drawable.b1_on,
                R.drawable.b2_on, R.drawable.b3_on,R.drawable.b1_on,
                R.drawable.b2_on, R.drawable.b3_on, R.drawable.b5_on,R.drawable.b6_on, R.drawable.b7_on};
        cmdRect = new Rect[PageS.page[pageno].totalIconNum];
        int rectLeft,rectTop,rectRight,rectBottom,iconNum=0;
        for( int ii=0;ii< PageS.page[pageno].totalIconNum;ii++) {
            cmdRect[ii] =  PageS.page[pageno].icon[ii].iconRect ;
        }



      /*  switch (currentPage) {
            case 0:
                s0();
                break;
            case 1:
                s1();
                break;
            case  2:
                s2();
            case  3:
                s3();
                break;
            default:
                break;
        }*/
    }
}


             /*
                     int rectLeft,rectTop,rectRight,rectBottom;
        for( ii=0;ii< 20;ii++){
            if((MainActivityf.byte13Bin[ii][1]==pageno+1) && (MainActivityf.byte13Bin[ii][15]==0x05)) {
                rectLeft = ((MainActivityf.byte13Bin[ii][2]&0xff)<<8) + (MainActivityf.byte13Bin[ii][3]&0xff);
                rectTop = ((MainActivityf.byte13Bin[ii][4]&0xff)<<8) + (MainActivityf.byte13Bin[ii][5]&0xff);
                rectRight = ((MainActivityf.byte13Bin[ii][6]&0xff)<<8) + (MainActivityf.byte13Bin[ii][7]&0xff);
                rectBottom =((MainActivityf.byte13Bin[ii][8]&0xff)<<8) + (MainActivityf.byte13Bin[ii][9]&0xff);
                jumpRect[jumpRectNum++] = new Rect(rectLeft, rectTop, rectRight,rectBottom);
            }
        }
         cmdRectNum=0;
        for( ii=0;ii< 20;ii++){
            if((MainActivityf.byte13Bin[ii][1]==pageno+1) && (MainActivityf.byte13Bin[ii][15]==0x02)) {
                rectLeft = ((MainActivityf.byte13Bin[ii][2]&0xff)<<8) + (MainActivityf.byte13Bin[ii][3]&0xff);
                rectTop = ((MainActivityf.byte13Bin[ii][4]&0xff)<<8) + (MainActivityf.byte13Bin[ii][5]&0xff);
                rectRight = ((MainActivityf.byte13Bin[ii][6]&0xff)<<8) + (MainActivityf.byte13Bin[ii][7]&0xff);
                rectBottom =((MainActivityf.byte13Bin[ii][8]&0xff)<<8) + (MainActivityf.byte13Bin[ii][9]&0xff);
                cmdRect[cmdRectNum++] = new Rect(rectLeft, rectTop, rectRight,rectBottom);
             }
        }

              if (!tmpstr.equals("")) {

             Message cmdmsg = new Message();
             cmdmsg.what = 1;
             Bundle bcmd = new Bundle();
             int index, index82,index5a;
             int cmdlenght;
             int tmpstrlenght = read_buf.length;

             do {
                 index = tmpstr.indexOf("5aa5");
                 tmpstrlenght = tmpstr.length();
                 if (index != -1) {
                     cmdlenght = ((int) tmpstr.charAt(index + 4) -48)* 16 + (int) tmpstr.charAt(index + 5) -48;
                     feedCamdstr = tmpstr.substring(index, index + (cmdlenght + 3) * 2);
                     feedCamdFalgstr =  feedCamdstr.substring(index+6, index + 8);
                     if (feedCamdFalgstr.contains("82") ) {//为有效反馈指令
                         bcmd.putString("alltext", feedCamdstr);
                         cmdmsg.setData(bcmd);
                         boolean xx = uHandler.sendMessage(cmdmsg);
                         break;
                     }
                     else {//为无效反馈指令
                         if ((index + (cmdlenght + 3) * 2) < tmpstrlenght)
                             tmpstr = tmpstr.substring(index + (cmdlenght + 3) * 2, tmpstrlenght);
                         else {
                             break;
                         }
                     }
                 } else {//无效
                     break;
                 }

             } while(!feedCamdFalgstr.contains("82"));
           /*  feedCamdFalgstr =  tmpstr.substring(6, 8);
             if (feedCamdFalgstr.contains("82") ) {//为有效反馈指令
                 bcmd.putString("alltext", feedCamdstr);
                 cmdmsg.setData(bcmd);
                 boolean xx = uHandler.sendMessage(cmdmsg);
             }*/




               /*      if (!tmpstr.equals("")) {
                             Message cmdmsg = new Message();
                             cmdmsg.what = 1;
                             Bundle bcmd = new Bundle();
                             int index, index82,index5a;
                             int cmdlenght;
                             int tmpstrlenght = read_buf.length;

                             index = tmpstr.indexOf("82");
                             index=index-6;
                             //index5a = tmpstr.indexOf("5a");
                             if (index != -1) {
                             System.out.println("字符串str中包含子串“82”" + index);
                             cmdlenght = ((int) tmpstr.charAt(index + 4) -48)* 16 + (int) tmpstr.charAt(index + 5) -48;
                             feedCamdstr = tmpstr.substring(index,  index+(cmdlenght + 3) * 2);
                             index5a = feedCamdstr.indexOf("5a");
                             if (index5a != -1) {
                             bcmd.putString("alltext", feedCamdstr);
                             cmdmsg.setData(bcmd);
                             boolean xx = uHandler.sendMessage(cmdmsg);
                             }
                             }
                             }
               public static int[] getImageWidthHeight(String path){
                   BitmapFactory.Options options = new BitmapFactory.Options();
                   /**
                    * 最关键在此，把options.inJustDecodeBounds = true;
                    * 这里再decodeFile()，返回的bitmap为空，但此时调用options.outHeight时，已经包含了图片的高了

                   options.inJustDecodeBounds = true;
                   Bitmap bitmap = BitmapFactory.decodeFile(path, options); // 此时返回的bitmap为null
                   /**
                    *options.outHeight为原始图片的高

                   return new int[]{options.outWidth,options.outHeight};
               }*/